#!/usr/bin/env python
# -*- coding:utf-8 -*-
from base import globalvars as glo
from base.config_tool import ConfigTool
from base.ui.base_ui import BaseUI

# 调用BaseUI封装登录页面模块
class LoginPage(BaseUI):
    url = glo.get_value("url1")+"/login"
    # Standard 类型登录
    p_type = "xpath=>//div[contains(text(),'账号密码登录')]"
    # 用户名输入框
    p_username = "xpath=>//input[@placeholder='手机号/邮箱']"
    # 密码输入框
    p_password = "xpath=>//input[@placeholder='请输入密码']"
    # 登录按钮
    p_login = "xpath=>(//button/span)[last()]"


    # 打开url
    def m_open(self):
        self.get(self.url)

    # 选择Standard 类型登录
    def click_login_type(self):
        self.click(self.p_type)

    # 输入用户名
    def m_username(self,username ):
        self.send_keys(self.p_username, username)

    # 输入密码
    def m_password(self, password):
        self.send_keys(self.p_password, password)

    # 点击登录按钮
    def m_login(self):
        self.click(self.p_login)


# 获取用户名和密码
config_name = glo.get_value("config_name")
conf = ConfigTool(config_name)
username = conf.get_conf("User", "username")
password = conf.get_conf("User", "password1")
def user_login():
    login = LoginPage()
    login.m_open()
    login.click_login_type()
    login.m_username(username)
    login.m_password(password)
    login.m_login()